#include <iostream>
#include <memory>
#include "Route.hpp"
#include "UdpServer.hpp" 
#include "ThreadPool.hpp"

using namespace ThreadPoolModule;

string defaulthandler(const string& msg)
{
    string hello="Hello";
    hello+=msg;
    return hello;
}


using task_t=std::function<void()>;
int main(int argc,char* argv[])
{
    if(argc!=2)
    {
        cerr<<"Usage"<<argv[0]<<"port"<<endl;
        exit(1);
    }

    uint16_t port=stoi(argv[1]);

    Enable_Console_Log_Strategy();
    Routine route;
    auto tp =ThreadPool<task_t>::GetInstance();
    unique_ptr<UdpServer> usvr=make_unique<UdpServer>(port,[&route,tp](int sockfd,const string& msg,InetAddr& peer)
    {
        task_t t=bind(&Routine::MessageRoute,&route,sockfd,msg,peer);
        tp->Enqueue(t);
        tp->Enqueue(t);

    });
    usvr->Init();
    usvr->Start();
}
